Markdown

Markdown is a way to make fancy documnets. make sure you “knit” often – after every major chnage – to mitigate errors. Hashtags are how me make section levels of a doc.

Next level

Next level

Next level

Next level

Basic Formatting

This is bold. (that’s double asterisks) or italics. (that’s single asterisks) Or code.(that’s back quotes)

  1. this is a numbers list
  2. second item.

To add a hyper link, do [link text](url). For example, go here

To link to sections of your document, do [link text](#section-name), no spaces! hyphens. For example, go here.

To add more verticle space between blocks of text, use this:  

 

 

Should be more space now.

** To include an image ** first put an image inside the foulder where your Rmd file is located. Then type ![](full_image_filename_here){width="50%"}

RMarkdown

RMarkdown is just Markdown with R code woven in.

You can do R stuff in the same line as text. For example. 6 will show as 6 (it would look like backtick lower-case-r space the code then backtick)

You could also do a full-milti-line CHUNK of R stuff:

# ```{r}
3+3
## [1] 6
#```

Settings to controle how R chunks appear:

  • eval=TRUE: which actually runs the code; if FALSE, it shows the code but doesn’t run it.

  • echo=TRUE : which shows the code; if FALSE, the code can run without being seen.

  • warnings=FALSE: which will turn off warnings.

  • fig.cap = "figure capption" adds a figure caption.

  • fig.width = 7 example of figure width.

  • fig.height = 4 example of figure height.

# this will be shown but not run
3+3 
## [1] 8

Bringing in real data

getting data

To manualy set working directory while building up my Rmarkdown file, just gi to Session > set working directory > Source file location.

library(readr)
energy <- read_csv("../data/IRENA data.csv", skip=1) #ship=1 skips the first row that describes the data
## Rows: 67200 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Country/area, Technology, Data Type, Grid connection, Electricity s...
## dbl (1): Year
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

exploring data

library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
energy %>% names 
## [1] "Country/area"           "Technology"             "Data Type"             
## [4] "Grid connection"        "Year"                   "Electricity statistics"
energy %>% head
## # A tibble: 6 × 6
##   `Country/area` Technology      `Data Type`             `Grid connection`  Year
##   <chr>          <chr>           <chr>                   <chr>             <dbl>
## 1 Afghanistan    Total renewable Electricity Generation… On-grid            2000
## 2 Afghanistan    Total renewable Electricity Generation… On-grid            2001
## 3 Afghanistan    Total renewable Electricity Generation… On-grid            2002
## 4 Afghanistan    Total renewable Electricity Generation… On-grid            2003
## 5 Afghanistan    Total renewable Electricity Generation… On-grid            2004
## 6 Afghanistan    Total renewable Electricity Generation… On-grid            2005
## # ℹ 1 more variable: `Electricity statistics` <chr>
energy %>% tail
## # A tibble: 6 × 6
##   `Country/area` Technology `Data Type`                  `Grid connection`  Year
##   <chr>          <chr>      <chr>                        <chr>             <dbl>
## 1 Zimbabwe       Nuclear    Electricity Generation (GWh) On-grid            2019
## 2 Zimbabwe       Nuclear    Electricity Generation (GWh) On-grid            2020
## 3 Zimbabwe       Nuclear    Electricity Generation (GWh) On-grid            2021
## 4 Zimbabwe       Nuclear    Electricity Generation (GWh) On-grid            2022
## 5 Zimbabwe       Nuclear    Electricity Generation (GWh) On-grid            2023
## 6 Zimbabwe       Nuclear    Electricity Generation (GWh) On-grid            2024
## # ℹ 1 more variable: `Electricity statistics` <chr>
energy %>% pull(Technology) %>% unique %>%  sort
##  [1] "Biogas"               "Coal and peat"        "Geothermal energy"   
##  [4] "Natural gas"          "Nuclear"              "Offshore wind energy"
##  [7] "Oil"                  "Onshore wind energy"  "Renewable hydropower"
## [10] "Solar photovoltaic"   "Total non-renewable"  "Total renewable"